
package com.foreveross.fetl.web.action.preprocess;

import javax.inject.Inject;

import org.mortbay.jetty.Request;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.dayatang.querychannel.support.Page;
import com.foreveross.fetl.application.ILogMessageApplication;
import com.foreveross.fetl.vo.LogMessageVO;
import com.foreveross.fetl.web.action.BaseAction;

@Controller("logMessageAction")
@Scope("prototype")
public class LogMessageAction extends BaseAction {
		
	private static final long serialVersionUID = 1L;
	
	private LogMessageVO logMessageDTO = new LogMessageVO();
		
	@Inject
	private ILogMessageApplication logMessageApplication;
	
	public String list() {
		return "METHOD";
	}
	
	public String view(){
		String id=getRequest().getParameter("id");
		Boolean judge=false;
		try {
			   Integer.parseInt(id);
			   judge = true;
			} catch (NumberFormatException e) {
			   judge = false;
			  }
		if(judge == true){
			long ids = Long.parseLong(id);
			logMessageDTO=logMessageApplication.findByID(ids);
		}
		return "METHOD";
	}
	
	public String add() {
		logMessageApplication.create(logMessageDTO);
		dataMap.put("result", "success");
		return "JSON";
	}
	
	public String update() {
		logMessageApplication.update(logMessageDTO);
		dataMap.put("result", "success");
		return "JSON";
	}
	
	public String pageJson() {
		if(logMessageDTO.getExecuteTypeStr()!=null){
			logMessageDTO.setExecuteType(Integer.parseInt(logMessageDTO.getExecuteTypeStr()));
		}
		Page<LogMessageVO> all = logMessageApplication.pageQueryLog(logMessageDTO, page, pagesize);
		dataMap.put("Rows", all.getResult());
		dataMap.put("start", page * pagesize - pagesize);
		dataMap.put("limit", pagesize);
		dataMap.put("Total", all.getTotalCount());
		return "JSON";
	}
	
	public String delete() {
	    String idsString = getRequest().getParameter("ids");
        if(idsString != null){
            String[] idArrs = idsString.split(",");
            Long[] ids = new Long[idArrs.length];
            for (int i = 0; i < idArrs.length; i ++) {
            	  ids[i] = Long.parseLong(idArrs[i]);
            	  logMessageApplication.delete(ids[i]);              
           }
        }
        
		dataMap.put("result", "success");
		return "JSON";
	}
	
	public String get() {
		dataMap.put("data", logMessageApplication.findByID(logMessageDTO.getId()));
		return "JSON";
	}

	public LogMessageVO getLogMessageDTO() {
		return logMessageDTO;
	}

	public void setLogMessageDTO(LogMessageVO logMessageDTO) {
		this.logMessageDTO = logMessageDTO;
	}
	
	

}